package nci60.data.protein

import nci60.data.connected.*
import nci60.data.protein.uniprot.Uniprot

/**
 * Main class for storing general protein information from IPI database.
 * <p />
 * The name of the sql table is customized to 'proteins' <p />
 * <b>See Also:</b> {@link #mapping}
 *
 * @autor <a href="mailto:Florian.J.Auer@googlemail.com">Florian J. Auer</a>
*/
class Protein {
    /**
     * IPI identifier
     */
    String mainId
    
    /**
     * Version of the IPI identifier
     */
    Integer idVersion
    
    /**
     * Full description of the protein <p />
     * The property has a customized mapping as "varchar" with a maximum length of 500 <p />
     * <b>See Also:</b> {@link #mapping}
     */
    String description = ''
    
    /**
     * Amino acid sequence of the protein <p />
     * The property has a customized mapping as "text" with a maximum length of 2000 <p />
     * <b>See Also:</b> {@link #mapping}
     */
    String sequence = ''
    
    /**
     * Molecular weight of the protein (Da)
     */
    Integer weight
    
    /**
     * Organism from which the protein is originated
     * @see nci60.data.protein.SourceOrganism
     */
    SourceOrganism organism


    /**
     * GRAILS <a href="http://grails.org/doc/latest/guide/GORM.html#gormAssociation" target="_blank">Associations in Gorm</a>
     * <p />
     * <style>.custom-table td{border-top:1pt solid grey;vertical-align:top;} .custom-table{border-collapse:collapse;width:100%;}</style>
     * <table class="custom-table">
     * <tr><td>
     *              altNames
     * </td><td>        alternative (former or merged) IPI identifier <p />
     *                  <b>See Also:</b> {@link nci60.data.protein.ProteinAltName}
     * </td></tr>
     * <tr><td>
     *              chromosomes
     * </td><td>        chromosomal location of the protein <p />
     *                  <b>See Also:</b> {@link nci60.data.protein.ProteinChromosome}
     * </td></tr>
     * <tr><td>
     *              sourceReferences
     * </td><td>        reference to database entry, of which the aa sequence is retrieved <p />
     *                  <b>See Also:</b> {@link nci60.data.protein.ProteinReference} <p />
     *                  The relationship has a customized mapping as jointable "ipi_sourcereferences"<p />
     *                  <b>See Also:</b> {@link #mapping}
     * </td></tr>
     * <tr><td>
     *              referenceIds
     * </td><td>        reference to all other database entries, which are merged into this IPI entry <p />
     *                  <b>See Also:</b> {@link nci60.data.protein.ProteinReference} <p />
     *                  The relationship has a customized mapping as jointable "ipi_referenceids"<p />
     *                  <b>See Also:</b> {@link #mapping}
     * </td></tr>
     * <tr><td>
     *              peptides
     * </td><td>        connetion between general protein information and identified peptides via PeptideInProtein class <p />
     *                  <b>See Also:</b> {@link nci60.data.connected.PeptideInProtein}
     * </td></tr>
     * <tr><td>
     *              genes
     * </td><td>        gene names of the protein <p />
     *                  <b>See Also:</b> {@link nci60.data.protein.GeneName}
     * </td></tr>
     * <tr><td>
     *              uniprot
     * </td><td>        connection to (normaly one) uniprot entry. necessary as many relationship because of import and possibility of more than one Uniprot source <p />
     *                  <b>See Also:</b> {@link nci60.data.protein.uniprot.Uniprot} <p />
     *                  The relationship has a customized mapping as column "protein_id" in the uniprot class (on the many side)<p />
     *                  <b>See Also:</b> {@link #mapping}
     * </td></tr>
     * </table>
     */	
    static hasMany = [altNames : ProteinAltName, 
                    chromosomes:ProteinChromosome, 
                    referenceIds:ProteinReference,
                    sourceReferences:ProteinReference,
                    peptides:PeptideInProtein,
                    //suggestions:Suggestion,
                    genes:GeneName,
                    uniprot:Uniprot]

    /**
     * GRAILS <a href="http://grails.org/doc/latest/guide/single.html#constraints" target="_blank">Declaring Constraints</a>
     * <p />
     * Constraints in Grails are a way to declaratively specify validation rules for generating objects in GORM.
     */	
    static constraints = {
    }

    /**
     * GRAILS <a href="http://grails.org/doc/latest/guide/GORM.html#ormdsl" target="_blank">Custom ORM Mapping</a>
     * <p />
     * Grails domain classes can be mapped onto many legacy schemas with an Object Relational Mapping DSL (domain specific language). 
     */	
    static mapping = {
            table 'proteins'
            version false
            sequence(sqlType:"text", lenght:2000)
            description(sqlType:"varchar(500)")
            sourceReferences joinTable: 'ipi_sourcereferences'
            referenceIds joinTable: 'ipi_referenceids'
            uniprot column: 'protein_id'
    }

    /**
     * GRAILS default representation of the object as String
     * @return String representation of the object
     */	
    String toString() {
//		return "DBid: $id\n" +
//			"ID: $mainId.$version\n" +
//			"Description: $description\n" +
//			"Sequence: $sequence\n" +
//			"Source: $sourceReferences\n" +
//			"AltNames: $altNames\n" +
//			"Chromosomes: $chromosomes\n" +
//			"RefIds: $referenceIds\n"
            return mainId
    }
}
